package demo.util;


import java.io.File;
import java.io.FileFilter;

public class GetFilesInDirectory {
    public static void main(String[] args) {
        String directoryPath = "/path/to/directory";
        File directory = new File(directoryPath);
        File[] files = directory.listFiles(new FileExtensionFilter("txt"));
        if (files!= null) {
            for (File file : files) {
                System.out.println(file.getName());
            }
        }
    }
}

class FileExtensionFilter implements FileFilter {
    private String extension;

    public FileExtensionFilter(String extension) {
        this.extension = extension;
    }

    @Override
    public boolean accept(File file) {
        return file.getName().endsWith("." + extension);
    }
}
